Skip to content

feat(java): add Google Tink detection rules (AEAD, Mac, Hybrid, Signature)#407

Closed
Chennamma-Hotkar wants to merge 1 commit into
cbomkit:mainfrom
Chennamma-Hotkar:feature/java-tink-mac-hybrid-signature
Closed

feat(java): add Google Tink detection rules (AEAD, Mac, Hybrid, Signature)#407
Chennamma-Hotkar wants to merge 1 commit into
cbomkit:mainfrom
Chennamma-Hotkar:feature/java-tink-mac-hybrid-signature

Conversation

@Chennamma-Hotkar
Copy link
Copy Markdown

@Chennamma-Hotkar Chennamma-Hotkar commented May 9, 2026

Summary

Adds detection rules for Google Tink Java cryptography library covering all four major primitives: AEAD, MAC, hybrid encryption, and digital signatures. Tink is one of the most widely used Java cryptography libraries and previously had no detection coverage in this plugin.

This PR replaces #406 — that PR's AEAD work is included here in a single self-contained commit.

Architecture

Each primitive follows the same pattern:

  1. KeysetHandle.generateNew(template) is the primary detection point
  2. Primitive operations (encrypt/decrypt, computeMac/verifyMac,
    sign/verify) are attached as depending rules
  3. Each primitive maps to its correct context:
    • AEAD/Hybrid → CipherContext
    • Mac → MacContext
    • Signature → SignatureContext

Detection Coverage

Primitive Context Templates
AEAD CipherContext AES128_GCM, AES256_GCM, AES128_CTR_HMAC_SHA256, AES256_CTR_HMAC_SHA256
Mac MacContext HMAC_SHA256_128BITTAG, HMAC_SHA256_256BITTAG, HMAC_SHA512_256BITTAG, HMAC_SHA512_512BITTAG, AES_CMAC
Signature SignatureContext ECDSA_P256, ECDSA_P384, ECDSA_P521, ED25519, RSA_SSA_PKCS1_3072_SHA256_F4
Hybrid CipherContext ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM, ECIES_P256_HKDF_HMAC_SHA256_AES128_CTR_HMAC_SHA256

Testing

  • 161 tests pass, 0 failures
  • 8 skipped tests are pre-existing (present before this PR)
  • mvn spotless:check passes
  • mvn -B clean package -pl java passes
Screenshot 2026-05-09 101930

Follow-up (separate PR)

  • DeterministicAead operations
  • Additional AEAD templates (ChaCha20Poly1305, AES_SIV, AES_EAX)
  • KeysetHandle.newBuilder() pattern detection

@Chennamma-Hotkar Chennamma-Hotkar requested a review from a team as a code owner May 9, 2026 04:36
…imitives

Signed-off-by: Chennamma <channuhotkar@gmail.com>
@Chennamma-Hotkar Chennamma-Hotkar force-pushed the feature/java-tink-mac-hybrid-signature branch from 9d63d21 to 9581052 Compare May 10, 2026 14:09
@Chennamma-Hotkar Chennamma-Hotkar changed the title feat(java): extend Google Tink detection with Mac, Hybrid and Signature primitives feat(java): add Google Tink detection rules (AEAD, Mac, Hybrid, Signature) May 10, 2026
@fynnth
Copy link
Copy Markdown
Contributor

fynnth commented May 20, 2026

Hey @Chennamma-Hotkar ,

After going through the changes carefully, I have to be honest: this PR has some fundamental issues that prevent us from merging it, and they follow a pattern we've seen in your previous PRs. It looks like a lot of this was generated or assembled without a thorough understanding of how the detection engine actually works. I'd like to explain why, concretely, so you can fix it properly if you want to take another shot at this.

The detection rules don't actually distinguish templates and every rule across all four primitives is functionally identical:

.forObjectTypes("com.google.crypto.tink.KeysetHandle")
.forMethods("generateNew")
.withAnyParameters()

shouldBeDetectedAs(new ValueActionFactory<>("AES128_GCM")) is a label, not a filter condition. The engine never inspects the actual argument passed to generateNew(). This means a single call like KeysetHandle.generateNew(AeadKeyTemplates.AES128_GCM) fires multiple rules simultaneously and produces separate findings -> one labeled AES128_GCM, one labeled AES256_GCM, one labeled ECDSA_P256, and so on. That's not detection, that's noise.

The tests actually confirm this unintentionally // Noncompliant 4 on every generateNew() line means the author accepted 4 findings per call as correct behavior. It isn't.

The test assertions don't test anything meaningful

All four test classes share essentially the same asserts() body, and every one accepts any of all 16 possible values:

assertThat(value.asString()).isIn("AES128_GCM", "AES256_GCM", ..., "ECDSA_P256", ...);
TinkAeadTest testing AEAD detection considers "ECDSA_P256" a valid result. That alone shows the assertions aren't verifying correctness -> they're just checking that the engine ran. Compare this to how existing JCA/BC tests work: each findingId has specific assertions for the exact algorithm, key size, and mode detected. That's what proper detection testing looks like.

We'd genuinely welcome proper Tink support, but if you want to take this on, please do it comprehensively:

  • Figure out how the engine can discriminate between template constants (field references, not string literals) or discuss with us first if you're unsure
  • Write assertions per finding that verify the specific algorithm, key size, and mode -> not a catch-all isIn() list
  • Implement the translation for all four primitives, including extracting key sizes and modes from the template names

Happy to discuss the right approach here before you invest more time, just drop a comment.

@fynnth fynnth closed this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants